﻿using PLCS.Domain.Shared.Enums;

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace PLCS.App.Converts;

internal class DictionaryToStringConvert : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is Dictionary<string, YesNo> dictionary)
        {
            StringBuilder stringBuilder = new StringBuilder();

            int count = dictionary.Count;
            int currentIndex = 0;

            foreach (var pair in dictionary)
            {
                string key = pair.Key;
                YesNo status = pair.Value;

                stringBuilder.Append(key);
                stringBuilder.Append(": ");
                stringBuilder.Append(status.ToString());

                currentIndex++;

                if (currentIndex < count)
                {
                    stringBuilder.Append("; ");
                }
            }

            return stringBuilder.ToString();
        }

        return string.Empty;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}